﻿package com.wandian.controller
{
	import com.wandian.data.GameData;
	import com.wandian.model.socket.ServerPacketProxy;
	import com.wandian.model.vo.*;
	
	import flash.utils.ByteArray;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class SocketCommand extends SimpleCommand
	{
		private var _global:GameData;

		public function SocketCommand()
		{
			this._global=GameData.getInstance();
			return;
		} 

		override public function execute(notification:INotification):void
		{
			trace("[SocketCommand]收到网络命令：" + notification.getName());
			var serverPoxy:ServerPacketProxy=facade.retrieveProxy(ServerPacketProxy.NAME) as ServerPacketProxy;
			var body:Object=notification.getBody();
			var bodyData:Object=null;
			var _loc_4:PropVo=null;
			var _loc_5:Object=null;
			var playerVo:PlayerVo=null;
			var _loc_7:PlayerVo=null;
			var _loc_8:int=0;
			var userid:uint=0;
			super.execute(notification);
			var server:ServerPacketProxy=facade.retrieveProxy(ServerPacketProxy.NAME) as ServerPacketProxy;
			bodyData=notification.getBody();
			switch (notification.getName())
			{
				//连接网络
				case CLZNoticeName.SOCKETCOMMAND_CONNECT_SOCKET:
				{
					serverPoxy.connect(GameData.HOST, GameData.PORT);
					break;
				}
				//登录验证
				case CLZNoticeName.SOCKETCOMMAND_REQ_LOGIN:
				{
					serverPoxy.requestLogin({userid: body.userid, password: body.password,key:body.key});
					break;
				}
				//发送消息
				case CLZNoticeName.SOCKETCOMMAND_REQ_SENDMESSAGE:
				{
					serverPoxy.requestSendMessage({userid: body.userid, type: body.type, message: body.message});
					break;
				}
				case CLZNoticeName.SOCKETCOMMAND_REQ_TESTAUTOADD:
				{
				serverPoxy.testAutoAddHandler(bodyData);
//				serverPoxy.requestTestAutoAdd();
				break;
				}

				case CLZNoticeName.SOCKETCOMMAND_FRIEND_LIST_REQ: //请求好友列表
				{
					break;
				}
				case CLZNoticeName.SOCKETCOMMAND_ROOM_LIST_REQ: //请求房间列表
				{
					serverPoxy.requestRoomList();
					break;
				}
				case CLZNoticeName.CONNECT_SOCKET:
				{
					server.connect(GameData.HOST, GameData.PORT);
					break;
				}
				case CLZNoticeName.REGISTER:
				{
					server.requestRoomInfo(bodyData as RoomVo);
					break;
				}
				case CLZNoticeName.REGISTER_MATCH:
				{
					break;
				}
				case CLZNoticeName.OUT_GAME_ROOM:
				{
					server.getOutRoom(bodyData);
					break;
				}
				case CLZNoticeName.SITDOWN:
				{
					server.sitRequest(bodyData);
					break;
				}
				case CLZNoticeName.SETROOMINFO:
				{
					server.setRoomInfoRequest(bodyData);
					break;
				}
				case CLZNoticeName.STAND_UP:
				{
					server.standSit(bodyData);
					break;
				}
				case CLZNoticeName.FLOD:
				case CLZNoticeName.CHECK:
				case CLZNoticeName.RAISE:
				case CLZNoticeName.CALL:
				case CLZNoticeName.ALLIN:
				{
					server.operationRequest(bodyData);
					break;
				}
				case CLZNoticeName.CHAT:
				{
					server.requestChat(bodyData.msg, bodyData.type);
					break;
				}
				case CLZNoticeName.AGAIN_SIT_BUYIN:
				{
					server.requestAgaingSitBuyIn(bodyData);
					break;
				}
				case CLZNoticeName.GIVE_CHIP_REQ:
				{
					server.requestGiveChip(bodyData);
					break;
				}
				case CLZNoticeName.GIVE_GIFT_REQ:
				{
					server.requestGiveGift(bodyData);
					break;
				}
				case CLZNoticeName.USE_PROP_REQ:
				{
					server.requestUseProp(bodyData);
					break;
				}
				case CLZNoticeName.UPDATE_PERSON_ID_REQ:
				{
					server.requestUpdatePesrson(bodyData as PropVo);
					break;
				}
				case CLZNoticeName.UPDATE_PERSON_HEAD_REQ:
				{
					server.requestUpdateHeadImage(bodyData as ByteArray);
					break;
				}
				case CLZNoticeName.RENEW_GIFT_REQ:
				{
					server.requestRenew(bodyData as PropVo);
					break;
				}
				case CLZNoticeName.GIFT_UPDATE_REQ:
				{
					_loc_4=bodyData as PropVo;
					_loc_5={toMid: this._global.userInfo.userVo.userid, pcate: _loc_4.pcate, pframe: _loc_4.pframe, type: 2};
					server.requestUseProp(_loc_5);
					break;
				}
				case CLZNoticeName.GIFT_CANCEL_REQ:
				{
					server.requestRemoveGift();
					break;
				}
				case CLZNoticeName.FRIEND_TO_REQUEST_REQ:
				{
					playerVo=bodyData as PlayerVo;
					server.requestToAddFriend(playerVo.userid);
					break;
				}
				case CLZNoticeName.FRIEND_RETURN_REQ:
				{
					_loc_7=bodyData as PlayerVo;
					_loc_8=int(notification.getType());
					server.requestReturnAddFriend(_loc_7.userid, _loc_8);
					break;
				}
				case CLZNoticeName.TRACK_ROOM:
				{
					userid=bodyData as uint;
					server.requestTrackRoom(userid);
					break;
				}
				case CLZNoticeName.FACE_REQ:
				{
					server.requestFace(bodyData.pcate, bodyData.pframe);
					break;
				}
				case CLZNoticeName.INIT_SET:
				{
					server.requestSet(notification.getBody() as int);
					break;
				}
				case CLZNoticeName.FAST_ENTER_GAME_REQ:
				{
					server.requestFastEnterRoomData();
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		} 

	}
}
